/*
 * Copyright 2007 National Bioinformatics Network
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package dgbgui.logging;

import java.util.Observable;

/**
 * @author bjnortier
 * The ErrorLogger is the central point where all errors and exceptions are logged.
 * Components that require notification of errors should observe the error logger.
 */
public class ErrorLogger extends Observable {
    
    /**
     * Log an exception error
     * @param e
     */
    public void logException(Exception e) {
        setChanged();
        if ( e.getCause() != null ) {
            notifyObservers(e.getCause().toString() + " : " + e.toString());
        } else {
            notifyObservers(e.toString());
        }
    }
    
    /**
     * Log a string error
     * @param msg
     */
    public void logString(String msg) {
        setChanged();
        notifyObservers(msg);
    }
    
    // ---------- Singleton pattern ----------- 
    
    public static ErrorLogger getInstance() {
        if ( m_instance == null ) {
            m_instance = new ErrorLogger();
        }
        return m_instance;
    }
    
    // Private for singleton
    private ErrorLogger() {
    }
    
    static ErrorLogger m_instance;
    

}
